package com.heima.wemedia.controller.v1;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.ChannelDto;
import com.heima.model.wemedia.pojos.WmChannel;
import com.heima.wemedia.fegin.WemediaClient;
import com.heima.wemedia.service.WmChannelService;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 频道信息表 前端控制器
 * </p>
 *
 *
 * @author itheima
 *
 */
@Slf4j
@RestController
@RequestMapping("/api/v1/channel")
public class WmChannelController {

    @Autowired
    private WmChannelService  wmChannelService;




    @GetMapping("/channels")
    public ResponseResult findAll(){
        return  ResponseResult.okResult(wmChannelService.list());
    }


    /*
    * 管理者平台的频道名称模糊分页查询
    * */
    @PostMapping("/list")
    public ResponseResult adminFindlist(@RequestBody ChannelDto channelDto){
        //wmChannelService.getList(channelDto);
        return wmChannelService.getList(channelDto);
    }

    /*
    * 保存频道
    * 前端传来的是AdChannel 由于和WmChannel一样，我直接用WmChannel来接收
    * */
    @PostMapping("/save")
    public ResponseResult saveChannel(@RequestBody WmChannel adChannel) {
        return wmChannelService.saveChannel(adChannel);
    }

    /*
     * 删除频道
     * **接口地址**:`/api/v1/channel/del/{id}`
     **请求方式**:`GET`
     */
    @GetMapping("/del/{id}")
    public ResponseResult deleteChannel(@PathVariable("id") Integer id) {
        return wmChannelService.deleteChannel(id);
    }

    /*
    * 修改频道
    * **接口地址**:`/api/v1/channel/update`
     **请求方式**:`POST`
     **请求数据类型**:`application/json`
    * */
    @PostMapping("/update")
    public ResponseResult updateChannel(@RequestBody WmChannel wmChannel) {

        return wmChannelService.updateChannel(wmChannel);
    }


}
